<template>
  <a-card :bordered="false">

    <!--金额统计区域-->
    <a-row>
      <a-col :span="8">
        <a-statistic title="入账金额总计(元)" :precision="2" :value="sumData.entryAmount" />
      </a-col>
      <a-col :span="8">
        <a-statistic title="退款金额总计(元)" :precision="2" :value="sumData.refundAmount" />
      </a-col>
      <a-col :span="8">
        <a-statistic title="提现金额总计(元)" :precision="2" :value="sumData.cashAmount" />
      </a-col>
    </a-row>
    <div style="margin-top: 20px;margin-bottom: 30px;">
      <a-badge status="processing" text="对账单统计的日期，以入账和出账时间为准，即资金加入账户，和资金离开账户的时间为准。当日的资金对账单将在次日的0点生成。" />
    </div>

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="对账日期">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" icon="download" @click="handleExportXls('资金对账单')" style="margin-left: 8px">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination"
        :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleRead(record)">查看</a>
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate.vue'
import { getAction, httpAction } from '@/api/manage'

export default {
  name: 'RmsFundList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate
  },
  data () {
    return {
      description: '资金对账单管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '入账金额',
          align: "center",
          dataIndex: 'entryAmount'
        },
        {
          title: '入账单数',
          align: "center",
          dataIndex: 'entryNum'
        },
        {
          title: '退款金额',
          align: "center",
          dataIndex: 'refundAmount'
        },
        {
          title: '退款单数',
          align: "center",
          dataIndex: 'refundNum'
        },
        {
          title: '提现金额',
          align: "center",
          dataIndex: 'cashAmount'
        },
        {
          title: '提现单数',
          align: "center",
          dataIndex: 'cashNum'
        },
        {
          title: '净销售金额',
          align: "center",
          dataIndex: 'profit'
        },
        {
          title: '对账日期',
          align: "center",
          dataIndex: 'date'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/rms/rmsFund/list",
        delete: "/rms/rmsFund/delete",
        query: "/rms/rmsFund/sum",
        deleteBatch: "/rms/rmsFund/deleteBatch",
        exportXlsUrl: "/rms/rmsFund/exportXls",
        importExcelUrl: "rms/rmsFund/importExcel",

      },
      sumData: {
        entryAmount: 0,
        refundAmount: 0,
        cashAmount: 0,
      },
      /* 排序参数 */
      isorter: {
        column: 'date',
        order: 'desc',
      },
      dictOptions: {},
    }
  },
  created () {
    this.querySum()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig () {
    },
    searchQuery () {
      this.loadData(1)
      this.querySum()
    },
    searchReset () {
      this.queryParam = {}
      this.loadData(1)
      this.querySum()
    },
    querySum () {
      getAction(this.url.query, { dayStart: this.queryParam.createTime_begin, dayEnd: this.queryParam.createTime_end, }).then(res => {
        if (res.code === 200) {
          this.sumData = res.result
        } else {
          this.$message.error(res.message)
        }
      })
    },
    handleRead (row) {
      this.$router.push({ path: '/sys/dz/fundlog', query: { date: row.date } })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>